﻿using STTech.BytesIO.Core;
using STTech.BytesIO.Serial;
using System.Text;

namespace ConsoleApp2
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            string ss = "eyJzdHVJZCI6IjE1NTYxNDIiLCJjb2RlIjoiazExLGsyMSxrMzEsazQyIiwibmFtZSI6Iua1i+ivlTEiLCJOciI6IjEyMzQ1Njc4OTExMjM0NTY3ODkxMTIzNDU2Nzg5MSJ9";

            await Console.Out.WriteLineAsync(Encoding.UTF8.GetString(Convert.FromBase64String(ss))); 
            await Console.Out.WriteLineAsync(ss.Length.ToString());
            SerialClient client = new SerialClient();

            client.PortName = "COM31";
            client.BaudRate = 115200;
            client.ReceiveBufferSize = 2000;
            client.SendBufferSize = 2000;
            client.OnDataReceived += Client_OnDataReceived;
            client.OnConnectedSuccessfully += Client_OnConnectedSuccessfully;
            client.OnDisconnected += Client_OnDisconnected;
            client.OnDataSent += Client_OnDataSent;
            client.OnExceptionOccurs += Client_OnExceptionOccurs;

            ConnectResult connectResult = await client.ConnectAsync();
            if (connectResult.IsSuccess)
            {
                await Console.Out.WriteLineAsync("连接成功");
            }
            Console.ReadLine();
        }

        private static void Client_OnExceptionOccurs(object? sender, ExceptionOccursEventArgs e)
        {

        }

        private static void Client_OnDataSent(object? sender, DataSentEventArgs e)
        {

        }

        private static void Client_OnDisconnected(object? sender, DisconnectedEventArgs e)
        {

        }

        private static void Client_OnConnectedSuccessfully(object? sender, ConnectedSuccessfullyEventArgs e)
        {

        }
        private static void Client_OnDataReceived(object? sender, DataReceivedEventArgs e)
        {

        }
    }
}
